<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    // 父类
    class Animal {
      name = ''
      age = 0

      constructor(name, age) {
        this.name = name
        this.age = age
      }
      eat(food) {
        console.log(`${this.name} 吃 ${food}`)
      }
    }

    // 子类
    class Dog extends Animal {
      price = 0

      constructor(name, age, price) {
        // 子类重写父类的话，必须在第一句调用父类的构造器
        super(name, age)
        this.price = price
      }

      eat(food, fruit) {
        console.log(`${this.name} 吃饭时配${fruit}`)
      }
    }
    // 不要实例化错对象
    const dog1 = new Dog('哈哈', 11, 100000)
    console.log(dog1)
    dog1.eat('葡式蛋挞', '草莓')
  </script>
</body>

</html>